<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"      
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">
	
    <h:body>	
		<ui:composition template="/admin/template.xhtml">		    			
		<p:panel header="Týmy">	
			<h:panelGrid columns="2">
				<p:panel header="Administrace týmů" style="min-width:500px;min-height: 1129px;">
					<h:panelGrid columns="1">	
							<p:panel header="Výběr Soutěže" style="min-width:500px;">	
							<h:form>	
								<h:panelGrid columns="2">
									<h:panelGroup>
										<h:outputText value="Sezóna : "/>
									</h:panelGroup>
									<h:panelGroup>													
										<p:selectOneMenu id="seasonSelect" value="#{searchTeamBean.selectedSeasonName}" style="width: 150px" >  
							                <f:selectItem  itemLabel="Vyberte sezónu" itemValue="" />  
							                <f:selectItems value="#{searchTeamBean.seasonNamesList}" />
							                <p:ajax  update="teamSelect" listener="#{searchTeamBean.handleSeasonChange}" /> 
				            			</p:selectOneMenu>			            			 
			            			</h:panelGroup>
									<h:panelGroup>
										<h:outputText value="Soutěž : "/>
									</h:panelGroup>
									<h:panelGroup>													
										<p:selectOneMenu id="teamSelect" value="#{searchTeamBean.selectedCompetionName}" style="width: 150px" >  
							                <f:selectItem itemLabel="Vyberte soutěž" itemValue="" />  
							                <f:selectItems value="#{searchTeamBean.competionNameList}" />
				            			</p:selectOneMenu>			            			 
			            			</h:panelGroup>            			
			            				<p:commandButton value="Hledej"  actionListener="#{searchTeamBean.fillTeamList}" update=":detailSouteze,:addCompetionForm,:growl"/>
			            			<h:panelGroup>
			            			</h:panelGroup>
			            		</h:panelGrid>
			            	</h:form>		
		            		</p:panel>
		            		<p:panel>            			
	            				<h:form id="detailSouteze" >
									<p:dataTable id="seasonCompetionTable" var="seasonCompetionTeam" value="#{searchTeamBean.teamList}" rowKey="#{seasonCompetionTeam.id}"  selection="#{searchTeamBean.selectedTeam}" emptyMessage="Žádné týmy nenalazeny" selectionMode="single" tableStyle="min-width:300px;">
								        <f:facet name="header">
											<c:if test="#{searchTeamBean.selectedCompetionName != ''}">
											<h:outputText value="Seznam týmů v soutěži "/>
											<h:outputText value="#{searchTeamBean.selectedCompetionName}"/>
											</c:if>
											<c:if test="#{searchTeamBean.selectedCompetionName != ''}">
											<h:outputText value=" v sezóně "/>
											<h:outputText value="#{searchTeamBean.selectedSeasonName}"/>
											</c:if>
								        </f:facet>
								        <p:column headerText="název týmu">  
								            <h:outputText value="#{seasonCompetionTeam.name}" />  
								        </p:column>
								        <p:column headerText="číslo">  
								            <h:outputText value="#{seasonCompetionTeam.number}" />  
								        </p:column>
								        <p:column headerText="hrací den">  
								            <h:outputText value="#{seasonCompetionTeam.playDay}" />  
								        </p:column>
								        <p:column headerText="čas">  
								            <h:outputText value="#{seasonCompetionTeam.playTime}" />  
								        </p:column>
								        <f:facet name="footer">  
							                <c:if test="#{searchTeamBean.selectedCompetionName != '' and searchTeamBean.selectedCompetionName != ''}">
							              		  <p:commandButton icon="ui-icon-document" value="přidat tým"  update=":form:" oncomplete="competionAddDialog.show()"/>
							         	     	  <p:commandButton icon="ui-icon-close" value="odebrat tým" actionListener="#{searchTeamBean.deleteTeamFromCompetion}" update=":detailSouteze,:addCompetionForm,:growl"/>  
							         	     	  <p:commandButton value="editovat tým" update=":form,:competionEditDialog,:editCompetionForm" oncomplete="competionEditDialog.show()"/>       
					       					</c:if>
					       				</f:facet> 
						  	        </p:dataTable>
					  	        </h:form>
					  	        <p:dialog id="dialogAddCompetion" header="Přidat soutěž do sezóny #{searchCompetionBean.selectedSeason}" widgetVar="competionAddDialog" resizable="false" width="500" showEffect="clip" hideEffect="fold" position="10,10">  
							      	 <h:form id="addCompetionForm">   
							      	    <h:panelGrid id="display" columns="2" cellpadding="4">
											<p:dataTable var="team" widgetVar="teamsAddTable" value="#{searchTeamBean.teamListAdd}"  paginatorAlwaysVisible="false" paginatorPosition="bottom"  paginator="true" rows="7" rowKey="#{team.id}"  selection="#{searchTeamBean.selectedTeamAdd}" selectionMode="single"  filteredValue="#{searchTeamBean.filteredTeams}" emptyMessage="Žádný tým nenalezen" tableStyle="min-width:300px;">
										        <f:facet name="header">
													<p:outputPanel>  
									            	      <h:outputText value="Hledat tým: " />  
									           		   	  <p:inputText id="globalFilter" onkeyup="teamsAddTable.filter()" style="width:150px" />  
									           		 </p:outputPanel>  
										        </f:facet>
										        <p:column id="modelHeader" filterBy="#{team.name}" filterStyle="display:none">  
										            <h:outputText value="#{team.name}" />  
										        </p:column>
										        <f:facet name="footer">
										           <p:selectOneMenu id="seasonSelect" value="#{searchTeamBean.playDay}" style="width: 80px" >  
										                <f:selectItem  itemLabel="Hrací den" itemValue="" />
										                <f:selectItem  itemLabel="sobota" itemValue="sobota" />  
										                <f:selectItem  itemLabel="nedele" itemValue="nedele" /> 
				            					   </p:selectOneMenu>
						            			   <h:outputText value="Hrací čas: " />
										           <p:inputMask value="#{searchTeamBean.playTime}" mask="99:99" style="width:50px" />
								        	 		
										           <h:outputText value="Číslo týmu: " />
										           <h:inputText value="#{searchTeamBean.number}" style="width:20px" required="true"/>
						            			   <p:commandButton value="Přidat" actionListener="#{searchTeamBean.addTeamToCompetion}" update=":detailSouteze,:growl,:addCompetionForm" oncomplete="competionAddDialog.hide()"/> 
					       						</f:facet>     
					  	   				 	</p:dataTable>
					  	   				 	
							        	</h:panelGrid>
							         </h:form>	
								</p:dialog>	 
								
								<p:dialog id="competionEditDialog" header="Editovat tým" widgetVar="competionEditDialog" resizable="false" width="200" showEffect="clip" hideEffect="fold" position="10,10">  
							      	 <h:form id="editCompetionForm">   
							      	    <h:panelGrid columns="1" cellpadding="2">
											       <p:selectOneMenu id="seasonSelect" value="#{searchTeamBean.selectedTeam.playDay}" style="width: 80px" >  
										                <f:selectItem  itemLabel="Hrací den" itemValue="" />
										                <f:selectItem  itemLabel="sobota" itemValue="sobota" />  
										                <f:selectItem  itemLabel="nedele" itemValue="nedele" /> 
				            					   </p:selectOneMenu>
				            			</h:panelGrid>
				            			<h:panelGrid columns="2">		   
						            			   <h:outputText value="Hrací čas: " />
										           <p:inputMask value="#{searchTeamBean.selectedTeam.playTime}" mask="99:99" style="width:50px" />
								        	 		
										           <h:outputText value="Číslo týmu: " />
										           <h:inputText value="#{searchTeamBean.selectedTeam.number}" style="width:20px" required="true"/>
						            			   <p:commandButton value="Upravit" actionListener="#{searchTeamBean.updateTeamToCompetion}" update=":detailSouteze,:growl,:competionEditDialog" oncomplete="competionEditDialog.hide()"/> 
					       				</h:panelGrid>
							         </h:form>	
								</p:dialog>
								           		    
							</p:panel>		  
					</h:panelGrid>
				</p:panel>
				<p:panel header="Editace týmů" style="min-height: 1129px;">   
				   <h:form id="form">	
					    	<p:dataTable id="competionTable" var="team" widgetVar="teamsTable" value="#{teamBean.teamsList}"  paginatorAlwaysVisible="false" paginatorPosition="bottom"  paginator="true" rows="14" rowKey="#{team.id}"  selection="#{teamBean.selectedTeam}" selectionMode="single"  filteredValue="#{teamBean.filteredTeams}" emptyMessage="Žádný tým nenalezen" tableStyle="min-width:300px;">
						        <f:facet name="header">
									<p:outputPanel>  
					            	      <h:outputText value="Hledat tým: " />  
					           		   	  <p:inputText id="globalFilter" onkeyup="teamsTable.filter()" style="width:150px" />  
					           		 </p:outputPanel>  
						        </f:facet>
						        <p:column headerText="Název týmu" filterBy="#{team.name}" filterStyle="display:none">  
						            <h:outputText value="#{team.name}" />  
						        </p:column>
						        <p:column headerText="Zkrácený název týmu">  
						            <h:outputText value="#{team.frontName}" />  
						        </p:column>
						        <p:column headerText="Přidělený uživatel" filterBy="#{team.user.username}" filterStyle="display:none">  
						            <h:outputText value="#{team.user.username}" />  
						        </p:column>
						        <f:facet name="footer">  
					            	<p:commandButton icon="ui-icon-pencil" value="editace" actionListener="#{teamBean.setupUsername}" update=":dialog" oncomplete="competionDialog.show()"/>
					                <p:commandButton icon="ui-icon-document" value="nový"  update=":form:" oncomplete="competionNewDialog.show()"/>
					            </f:facet>     
					  	    </p:dataTable>  
					</h:form>
					<p:dialog id="dialog" header="Editace" widgetVar="competionDialog" resizable="false"  
					              width="350" showEffect="clip" hideEffect="fold" position="10,10">  
						      	 <h:form>   
						      	    <h:panelGrid id="display" columns="2" cellpadding="4">
						      	       <h:outputText value="Název týmu:" />    						      
							           <h:inputText value="#{teamBean.selectedTeam.name}" style="width:230px"/>  
							           <h:outputText value="Zkrácený název týmu:" />    						      
							           <h:inputText value="#{teamBean.selectedTeam.frontName}" style="width:230px"/>  
							           <h:outputText value="Přidělený uživatel:" />  
							           <p:selectOneMenu value="#{teamBean.selectedUSername}" style="width: 150px" >  
							              <f:selectItem itemLabel="Vyberte uživatele" itemValue="" />  
							           <f:selectItems value="#{teamBean.usernameList}" />
				            			</p:selectOneMenu>	 	 
						        	</h:panelGrid> 
						        	<p:commandButton value="Ulož změny"  actionListener="#{teamBean.updateTeam}" update=":form,:growl" oncomplete="competionDialog.hide()"/> 
						        </h:form>	
					 </p:dialog>
				     <p:dialog id="dialogNew" header="Nový tým" widgetVar="competionNewDialog" resizable="false"  
					              width="350" showEffect="clip" hideEffect="fold" position="10,10">  
						      	 <h:form>   
						      	    <h:panelGrid id="display" columns="2" cellpadding="4">
						      	       <h:outputText value="Název týmu:" />    						      
							           <h:inputText value="#{teamBean.newTeam.name}" style="width:230px"/>    	 
						        	</h:panelGrid>
						        	<h:panelGrid columns="2" cellpadding="4">
						      	       <h:outputText value="Zkrácený název týmu:" />    						      
							           <h:inputText value="#{teamBean.newTeam.frontName}" style="width:230px"/>    	 
						        	</h:panelGrid> 
						        	<p:commandButton value="Ulož změny"  actionListener="#{teamBean.createTeam}" update=":form,:dialogNew,:growl" oncomplete="competionNewDialog.hide()"/> 
						        </h:form>	
					</p:dialog>
				</p:panel>
			</h:panelGrid>
		</p:panel>			
		</ui:composition>	
	</h:body>
</html>